// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   TemplateFlow.java

package com.oa.flow;

import com.oa.database.*;
import java.sql.*;

public class TemplateFlow
{

    private int template_id;
    private int before_id;
    private int node_id;
    private String swlb;
    private DataConn dataConn;
    private Connection conn;
    private int template_errcode;
    private String template_errstr;

    public TemplateFlow(DataConn dataConnection)
    {
        template_id = 0;
        before_id = 0;
        node_id = 0;
        swlb = "";
        dataConn = null;
        conn = null;
        template_errcode = 0;
        template_errstr = "";
        dataConn = dataConnection;
    }

    public void setTemplateId(int id)
    {
        template_id = id;
    }

    public void setBeforeId(int id)
    {
        before_id = id;
    }

    public void setNodeId(int id)
    {
        node_id = id;
    }

    public void setSwlb(String swlb)
    {
        swlb = swlb;
    }

    private void setErrorMessage()
    {
        template_errcode = dataConn.getErrorCode();
        template_errstr = dataConn.getErrorMessage();
    }

    public int getErrorCode()
    {
        return template_errcode;
    }

    public String getErrorMessage()
    {
        return template_errstr;
    }

    public void insertNode(int iTemplateId, int iBeforeId, int iNodeId, String sSwlb, String sState)
    {
        setTemplateId(iTemplateId);
        setBeforeId(iBeforeId);
        setNodeId(iNodeId);
        int NodeOrder = NodeOrder(iTemplateId, iBeforeId, sSwlb);
        NodeOrder++;
        sortNode(iTemplateId, iNodeId, NodeOrder, sSwlb, sState);
        UpdateData updateData = new UpdateData(dataConn);
        String sTable = "OA_GYMBLC_JD";
        String sUpdateStr = "JDSX=" + NodeOrder;
        String sCondition = "LCID=" + iTemplateId + "  and  JDID=" + iNodeId + "  and  SWLB='" + sSwlb + "'";
        updateData.update(sTable, sUpdateStr, sCondition);
    }

    public int deleteNode(int iTemplateId, int iNodeId, String sSwlb, String sState)
    {
        setTemplateId(iTemplateId);
        setNodeId(iNodeId);
        String sTable = "OA_GYMBLC_JD";
        String sConditionStr = "  LCID=" + iTemplateId + " and  JDID=" + iNodeId + " and  SWLB='" + sSwlb + "'";
        int NodeOrder = NodeOrder(iTemplateId, iNodeId, sSwlb);
        try
        {
            DeleteData deleteData = new DeleteData(dataConn);
            deleteData.delete(sTable, sConditionStr);
            template_errstr = deleteData.getErrorMessage();
        }
        catch(Exception e)
        {
            template_errstr = e.getMessage().toString();
        }
        sortNode(iTemplateId, iNodeId, NodeOrder, sSwlb, sState);
        return 0;
    }

    public void sortNode(int iTemplateId, int iNodeId, int NodeOrder, String sSwlb, String sState)
    {
        String sTable = "";
        String sUpdateStr = "";
        String sConditionStr = "";
        UpdateData updateData = new UpdateData(dataConn);
        sTable = "OA_GYMBLC_JD";
        if(sState.equals("add"))
            sUpdateStr = " JDSX = JDSX + 1 ";
        else
            sUpdateStr = " JDSX = JDSX - 1 ";
        sConditionStr = "LCID=" + iTemplateId + "  and   Swlb='" + sSwlb + "' and  JDSX>=" + NodeOrder;
        updateData.update(sTable, sUpdateStr, sConditionStr);
    }

    public int NodeOrder(int iTemplateId, int iNodeId, String sSwlb)
    {
        String sTable = "";
        String sField = "";
        String sCondition = "";
        int NodeOrder = 0;
        QueryData queryData = new QueryData(dataConn);
        sTable = "OA_GYMBLC_JD";
        sField = "JDSX";
        sCondition = "LCID=" + iTemplateId + "  and  JDID=" + iNodeId + " and  SWLB='" + sSwlb + "'";
        try
        {
            queryData.setMultRecordSet(sTable, sField, sCondition);
            ResultSet rs = queryData.getResultSet();
            if(rs.next())
                NodeOrder = rs.getInt("JDSX");
        }
        catch(SQLException ex)
        {
            template_errstr = ex.getMessage();
            template_errcode = ex.getErrorCode();
        }
        return NodeOrder;
    }

    public static void main(String args1[])
    {
    }
}
